package com.bc.bczbweb.controller.Ajax;

import com.bc.bcapi.service.T_SequenceService;
import com.bc.bcmodel.domain.T_Mnguser_infoModel;
import com.bc.commoncore.util.ConvertUtils;
import com.bc.commoncore.util.DateUtil;
import com.bc.commoncore.util.StringUtils;
import com.bc.commonentity.common.JsonResult;
import com.bc.bcapi.service.T_Menu_infoService;
import com.bc.bcmodel.domain.T_Menu_infoModel;
import com.bc.commonentity.enums.SeqNameEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.unidal.helper.Dates;

import javax.ws.rs.POST;
import java.math.BigInteger;

@RestController
@RequestMapping("ajax/t_menu_info")
public class AjaxT_Menu_infoController {
    @Autowired
    T_Menu_infoService t_Menu_infoService;

    @Autowired
    T_SequenceService t_SequenceService;

    @POST
    @RequestMapping(value = "add", method = RequestMethod.POST)
    public JsonResult add(T_Menu_infoModel req) {
        JsonResult js = new JsonResult();
        if (req.getMenu_id().equals("")) {
            req.setMenu_id(t_SequenceService.genSequence(SeqNameEnum.MANAGE_MENU_SEQ));
            t_Menu_infoService.insert(req);
        } else {
            req.setModify_time(DateUtil.getToday());
            t_Menu_infoService.update(req);
        }
        return js;
    }

    @RequestMapping(value = "del", method = RequestMethod.POST)
    public JsonResult del(String menu_id) {
        JsonResult js = new JsonResult();
        T_Menu_infoModel model = new T_Menu_infoModel();
        model.setMenu_id(menu_id);
        T_Menu_infoModel result = t_Menu_infoService.findByNamedParam(model);

        model = new T_Menu_infoModel();
        model.setMenu_id(menu_id);
        String status = "1";
        if (result.getStatus().equals("1")) {
            status = "0";
        }
        model.setStatus(status);
        t_Menu_infoService.update(model);
        return js;
    }
}